<template>
  <!-- 文章项容器 -->
  <div class="article-list">
    <!-- 文章项 -->
    <div class="article-item">
      <div
        class="taps"
        v-if="itemData.articlePersonalCategoryName || itemData.tags"
      >
        <div class="traingle" v-if="itemData.articlePersonalCategoryName"></div>
        <span class="text">{{ itemData.articlePersonalCategoryName }}</span>
        <span class="tag" v-for="item in itemData.tags" :key="item.id">
          {{ item.name }}</span
        >
      </div>
      <h3
        class="title"
        @click="
          goArticleDetail(itemData.id, {
            authorAvatar: itemAvatar.authorAvatar,
            authorId: itemData.authorId
          })
        "
      >
        {{ itemData.subject }}
      </h3>
      <div class="infos">
        <div class="left-infos">
          <img :src="itemAvatar.authorAvatar" />
          <span class="author-name">{{ itemData.authorNickName }}</span>
          <span class="write-time">{{
            itemData.createDate.split('T')[0]
          }}</span>
        </div>

        <div class="right-nums">
          <span class="num">{{ itemData.voteCount }}</span>
          <span>推荐</span>
          <span class="point"></span>
          <span class="num">{{ itemData.viewCount }}</span>
          <span>阅读</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'

export default {
  name: 'ArticleItem',
  mounted() {},
  props: {
    itemData: Object,
    // 头像数据
    itemAvatar: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  methods: {
    goArticleDetail(articleId, author) {
      this.setAuthor(author)
      this.$router.history.push({
        name: 'ArticleDetail',
        params: {
          articleId
        }
      })
    },
    ...mapActions('article', ['setAuthor'])
  }
}
</script>

<style scoped>
.article-list .article-item {
  padding: 16px 0;
  border-bottom: 1px dashed #dae1e7;
}
.article-item .taps {
  padding-left: 14px;
  position: relative;
}
.taps .traingle {
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  position: absolute;
  border-left: 6px solid #4684e2;
  border-right: none;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
}
.taps .text {
  margin-right: 24px;
  border-color: #dae1e7;
  color: #5f77a6;
}
.taps .tag {
  margin-right: 8px;
  border: 1px solid #a1adc5;
  box-sizing: border-box;
  border-radius: 16px;
  color: #152844;
  padding: 0 12px;
  height: 22px;
  line-height: 20px;
  display: inline-block;
}
h3.title {
  font-weight: 600;
  font-size: 18px;
  height: 28px;
  line-height: 28px;
  color: #152844;
  margin: 12px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.infos {
  display: flex;
  overflow: hidden;
  height: 28px;
  line-height: 28px;
  justify-content: space-between;
}
.infos .left-infos {
  display: flex;
}
.infos img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  margin-right: 8px;
  display: inline-block;
}
.infos .author-name {
  color: #152844;
  font-size: 14px;
  margin-right: 16px;
}
.infos .write-time {
  font-size: 12px;
  color: #5f77a6;
}
.infos .right-nums {
  color: #6f6f6f;
  font-size: 14px;
}
.right-nums .num {
  margin-right: 2px;
  color: #4684e2;
}
.right-nums .point {
  margin: 0 8px;
  display: inline-block;
  width: 4px;
  height: 4px;
  background: #c4c4c4;
  border-radius: 50%;
  vertical-align: middle;
}
</style>
